#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    this->setAcceptDrops(true);
    ui->setupUi(this);
    env = new environment();
    envInfo = new EnvironmentInfo();
    tmpProc = new TempProcess();

}
std::pair<int,QString> MainWindow::getStatus()
{
    return std::make_pair(status,statusMap.at(status));
}
void MainWindow::setStatus(int s)
{
    status = s;
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
        if (event->mimeData()->hasUrls()) {
            event->acceptProposedAction();
        }
  }
void MainWindow::dropEvent(QDropEvent *event) {
       QList<QUrl> urls = event->mimeData()->urls();
       for (const QUrl &url : urls) {
           QString fileName = url.toLocalFile();
           //qDebug() << "Dropped file:" << fileName;
       }
   }
void MainWindow::changeMode(int mode)
{
    this->mode = mode;
}
int MainWindow::getMode()
{
    return this->mode;
}
MainWindow::~MainWindow()
{
    delete ui;
}
EnvironmentInfo* MainWindow::getCurrEnvironment()
{
    return envInfo;
}
EnvironmentInfo* MainWindow::selectEnvironment(int index)
{
    EnvironmentInfo *t = env->selectEnvironment(index);
    if(t!= nullptr)
    {
        selectedIndex = index;
        envInfo = t;
        return envInfo;
    }
    else
    {
        return nullptr;
    }
}
void MainWindow::saveCurrentEnvironment(EnvironmentInfo *t)
{
    env->updateEnvironment(selectedIndex,t);
}
void MainWindow::setTempProcess(TempProcess* p)
{
    tmpProc =  p;
}
TempProcess* MainWindow::getTempProcess()
{
    return tmpProc;
}
std::map<int,EnvironmentInfo*>* MainWindow::getEnvLists()
{
    return env->getEnvironmentLists();
}
